package com.ccsoft.netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @author chanchaw
 * @create 2022-07-18 8:03
 */
public class ServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        // 通过通道得到管道
        ChannelPipeline pipeline = socketChannel.pipeline();
        // 指定 http 协议编解码
        pipeline.addLast("MyHttpServerCodec",new HttpServerCodec());
        // 指定自定义的服务端处理 handler
        pipeline.addLast("MyServerHandler",new ServerHandler());
    }
}
